define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dormitory/image/index',
                    add_url: '',
                    edit_url: 'dormitory/image/edit',
                    del_url: 'dormitory/image/del',
                    multi_url: '',
                }
            });

            var table = $("#table");

            Template.helper("Moment", Moment);

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                templateView: true,
                //禁用默认搜索
                search: false,
                //启用普通表单搜索
                commonSearch: false,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: false,
                //分页大小
                pageSize: 12,
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        // {
                        //     field: 'a.dorm_number', title: __('园区'), searchList: function (column) {
                        //     return Template('gardenTpl', {});
                        // }, formatter: function (value, row, index) {
                        //     return '无';
                        // }, visible: false
                        // },
                        {field: 'garden_name', title: '园区', operate: false},
                        {field: 'building_name', title: __('楼栋'), operate: false},
                        {field: 'dorm_number', title: __('寝室号'), operate: false},
                        {field: 'url', title: __('图片'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ],
                ],

            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            //点击详情
            $(document).on("click", ".btn-edit[data-id]", function () {
                Backend.api.open('example/bootstraptable/detail/ids/' + $(this).data('id'), __('Detail'));
            });

        },
        detail: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: '',
                    detail_url: 'dormitory/image/detail' + '/ids/' + Config.ids,
                    add_url: '',
                    edit_url: '',
                    del_url: 'dormitory/image/del',
                    multi_url: '',
                }
            });

            var table = $("#table");

            Template.helper("Moment", Moment);

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.detail_url,
                templateView: true,
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'garden_name', title: '园区', operate: false},
                        {field: 'building_name', title: __('楼栋'), operate: false},
                        {field: 'dorm_number', title: __('寝室号'), operate: false},
                        {field: 'url', title: __('图片'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ],
                ],
                //禁用默认搜索
                search: false,
                //启用普通表单搜索
                commonSearch: false,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: false,
                //分页大小
                pageSize: 12,
                showToggle: false,
                showColumns: false,
                showExport: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            //点击详情
            $(document).on("click", ".btn-detail[data-id]", function () {
                Backend.api.open('example/bootstraptable/detail/ids/' + $(this).data('id'), __('Detail'));
            });

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {

            },
            events: {

            }
        }
    };
    return Controller;
});